from apps.merchant.item.baseViews import *

class ItemViewForCSet(BaseItemViewSet):
    authentication_classes = []
    permission_classes = []
    def get_queryset(self):
        params = getRequestParams(self.request)
        _list = getItemAll(self).filter(checkStatus='PASS').exclude(status=0)
        if params.get('routeName') == 'giftSection':
            _list = _list.filter(activity__id=31)
        if params.get('cate'):
            _list = _list.filter(activity__isnull=True)
        return _list

    @action(methods=['post'], detail=False)
    def getItemsByIds(self, request):
        params = getRequestParams(self.request)
        ids = params.get('ids')
        if type(ids) != list:
            return Response(response_message('ids参数格式错误'))
        _list = getItemAll(self).filter(id__in=ids).filter(checkStatus='PASS').exclude(status=0)
        return Response(response_success({'list': ItemModelSerializer(_list, many=True, context={'request':request}).data}))
